<template>
  <div class="companyinterviewdetail">
    <el-row>
      <el-col :span="24">
        <el-table :data="dataList" border @row-dblclick="view">
          <el-table-column type="index" :label="$t('index')" width="70" align="center"></el-table-column>
          <el-table-column prop="real_name" label="姓名" align="center" width="110"></el-table-column>
          <el-table-column prop="position_name" label="邀请职位" align="center"></el-table-column>
          <el-table-column prop="sex" label="性别" align="center" :formatter="formatterSex"></el-table-column>
          <el-table-column prop="education" label="学历" align="center" :formatter="formatterEducation"></el-table-column>
          <el-table-column prop="notice_time" label="通知时间" align="center" width="120"></el-table-column>
          <el-table-column label="操作" align="center" width="140">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="light" content="编辑" placement="top">
                <i class="fa fa-pencil icon-style" aria-hidden="true" @click="edit(scope.row)"></i>
              </el-tooltip>
              <el-tooltip class="item" effect="light" content="删除" placement="top">
                <i class="fa fa-times icon-style" @click="Delete(scope.row)"></i>
              </el-tooltip>
              <el-tooltip class="item" effect="light" content="查看" placement="top">
                <i class="fa fa-eye icon-style" aria-hidden="true" @click="view(scope.row)"></i>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-pagination @current-change="handleCurrentChange" layout="total, prev, pager, next" :total="total"
                   class="table-page-style"></el-pagination>
    <el-Dialog :visible.sync="interviewdialogVisible" size="tiny">
      <CompanyInvitationDialog :id="currentId" :type="dialogType" @stateChange="CloseDialog"></CompanyInvitationDialog>
    </el-Dialog>
  </div>
</template>
<script>
  import { postDataToServer } from '../../assets/js/post.js'
  import { commonNotify } from '../../assets/js/common.js'
  import { getStaticMapList } from '../../assets/js/GlobeDefine.js'
  import ListToolBar from '../common/ListToolbar'
  import CompanyInvitationDialog from '@/components/companySendbox/CompanyInvitationDialog'

  export default {
    name: 'companyinterviewdetail',
    props: ['status'],
    data () {
      return {
        type: '1',
        total: 0,
        page_no: 1,
        page_size: 20,
        dialogType: 'edit',
        currentId: '',
        dataList: [],
        interviewdialogVisible: false
      }
    },
    created () {
      this.loadInvitationList(this.page_no)
    },
    methods: {
      //获取邀请函信息
      loadInvitationList (pageNum) {
        let _this = this
        let data = new Object()
        data.page_no = _this.page_no
        data.page_size = _this.page_size
        data.type = _this.type
        data.id = _this.$store.state.companyID
        if (_this.status !== 5) {
          data.status = _this.status
        }
        postDataToServer('HM_COMPANY_INTERVIEW_LISTPAGE', data)
          .then(function (res) {
            if (res.status === 0) {
              _this.total = res.data_list.length
              _this.dataList = res.data_list
            }
          })
          .catch(function (err) {
            _this.$message({
              message: err,
              type: 'error'
            })
          })
      },
      handleCurrentChange (pageNum) {
        this.page_no = pageNum
      },
      edit (row) {
        const date = new Date()
        let starttime = row.interview_time.replace(new RegExp('-', 'gm'), '/')
        starttime = (new Date(starttime)).getTime()
        if (starttime < date.getTime()) {
          this.$message({
            message: '面试时间已过，不能修改',
            type: 'warning'
          })
          return
        }
        this.currentId = row.id
        this.interviewdialogVisible = true
      },
      Delete (row) {
        let _this = this
        _this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let param = new Object()
          param.id = row.id
          postDataToServer('HM_COMPANY_INTERVIEW_DEL', param).then(function (res) {
            commonNotify(_this, res.status, 'DEL')
            _this.loadInvitationList(_this.page_no)
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      view (row) {
        this.$router.push({path: '/companysenddetail/' + row.resume_id})
      },
      formatterSex (row, column) {
        return getStaticMapList('sex', row.sex)
      },
      formatterEducation (row, column) {
        return getStaticMapList('education', row.education)
      },
      formatterStatus (row, column) {
        return getStaticMapList('view_status', row.status)
      },
      CloseDialog (state) {
        this.interviewdialogVisible = state
        this.currentId = ''
      }
    },
    components: {
      ListToolBar,
      CompanyInvitationDialog
    }
  }
</script>
<style>
  .background {
    margin-top: 0.9em;
    background-color: #FAFAFA;
  }

  .icon-style {
    font-size: 20px;
    color: #20a0ff;
    margin: 5px;
    cursor: pointer;
  }
</style>
